<?php
/**
 * Zhub - A PHP Framework For API Developer
 *
 * This file is part of the Zhub package.
 *
 * (c) YiLong Fan <fantiq@163.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author fanyilong <fantiq@163.com>
 * @copyright 2017 fanyilong. All rights reserved.
 * @package Zhub
 * @date 18-3-15
 */

namespace Zhub\Application\Http;

use Zhub\Application\Http\Event\AppEvent;
use Zhub\Application\Http\Server\HttpServer;
use Zhub\Application\Http\Server\DefaultServer;
use Zhub\Route\Route;

class Kernel
{
    public $request = null;

    public $server = null;

    public $route = null;

    public $event = null;

    public function __construct(HttpServer $server = null, Route $route = null, AppEvent $event = null)
    {
        $this->server = $server ?? new DefaultServer();
        $this->route = $route ?? Route::getInstance();
        $this->event = $event ?? AppEvent::getInstance();
        $this->request = $this->server->getRequest();
    }

    public function handle()
    {
        $this->event->fireChain($this);
    }

    public function getServer()
    {
        return $this->server;
    }
    public function getRoute()
    {
        return $this->route;
    }
    public function getEvent()
    {
        return $this->event;
    }
    public function getRequest()
    {
        return $this->request;
    }
}
